//
//  M4PagoDetailCell.swift
//  M4
//
//  Created by YuChuang on 2024/8/28.
//


enum M4PagoAction: Int {
    case M4ChannelAction = 0
    case M4ToProrrogaPageAction = 1
    case M4ProrrogaAction = 2
}

import UIKit

class M4PagoDetailCell: M4BaseTableViewCell {
    
    @IBOutlet weak var M4PagoDetailAmount: UILabel!
    
    @IBOutlet weak var M4PDProCellName: UILabel!
    
    @IBOutlet weak var M4PDProCellNormalAmount: UILabel!
    
    @IBOutlet weak var M4PDProCellPagaAmount: UILabel!
    
    @IBOutlet weak var M4PDProCellDaysLabel: UILabel!
    
    @IBOutlet weak var M4PDProCellDaysValue: UILabel!
    
    @IBOutlet weak var M4PDProCellPagoDate: UILabel!
    
    @IBOutlet weak var M4PDProrrogaButton: UIButton!
    
    private var orderModel: M4LoanOrderListModel?
    
    override func awakeFromNib() {
        super.awakeFromNib()
        M4PDProrrogaButton.isHidden = true
    }
    
    override func M4UpdateDataAndUI() {
        orderModel = data as? M4LoanOrderListModel
        M4PDProCellName.text = orderModel?.LcMnJMQqO
        let sonmodel = orderModel?.XPvy?[0]
        M4PagoDetailAmount.text = "$\(M4String.M4BlankAmount(original: "\(sonmodel?.GzVEQkxx ?? 0)"))"//待还
        M4PDProCellNormalAmount.text = "$\(M4String.M4BlankAmount(original: "\(sonmodel?.IYv ?? 0)"))"//正常应还
        M4PDProCellPagaAmount.text = "$\(M4String.M4BlankAmount(original: "\(sonmodel?.IVkd ?? 0)"))"//已还
        let days = sonmodel?.WSTaE ?? 0
        M4PDProCellDaysLabel.text = days >= 0 ? "Fecha de vencimiento" : "Días de retraso"
        M4PDProCellDaysLabel.textColor = days >= 0 ? COLOR_666666 : COLOR_9D0000
        M4PDProCellDaysValue.textColor = days >= 0 ? COLOR_333333 : COLOR_9D0000
        M4PDProCellDaysValue.text = days >= 0 ? "\(days)Días" : "\(abs(days))Días"
        let time = (sonmodel?.QwLOAltJy ?? 0) / 1000
        let date = Date(timeIntervalSince1970: TimeInterval(time))
        let formatter = DateFormatter()
        formatter.dateFormat = "dd-MM-yyyy"
        let dateString = formatter.string(from: date)
        M4PDProCellPagoDate.text = sonmodel?.fB3ngv ?? ""
        M4PDProrrogaButton.isHidden = orderModel?.TTkXKqx == 1 ? false : true
    }
    
    @IBAction func M4PDProrrogaAction(_ sender: UIButton) {
        M4CellActionDelegate?.M4CellAction(M4IDAction(actionType: M4PagoAction.M4ToProrrogaPageAction.rawValue, actionData: orderModel))
        sender.M4EventUnavailable = false
    }
    
    override func M4CellLeftRightEdge() -> CGFloat {
        return 0
    }
    
}
